package cn.life.common.support.datasource.config.properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author 李佳明
 * @Date 2018/6/18 0018.19:14.
 */
@Order(100)
@Component
@PropertySource({"classpath:datasource.properties"})
public class DruidDataSourcePoolProperties {

    /**
     * 初始化时建立物理连接的个数。初始化发生在显示调用init方法，或者第一次getConnection时
     */
    @Value("${jdbc.pool.initialSize}")
    private Integer initialSize;

    /**
     *  最大连接池数量
     */
    @Value("${jdbc.pool.maxActive}")
    private Integer maxActive;

    /**
     *  获取连接时最大等待时间，单位毫秒。配置了maxWait之后，缺省启用公平锁，并发效率会有所下降，如果需要可以通过配置useUnfairLock属性为true使用非公平锁。
     */
    @Value("${jdbc.pool.maxWait}")
    private Long maxWait;

    /**
     *  最小连接池数量
     */
    @Value("${jdbc.pool.minIdle}")
    private Integer minIdle;

    /**
     *  有两个含义：
     *  1) Destroy线程会检测连接的间隔时间
     *  2) testWhileIdle的判断依据，详细看testWhileIdle属性的说明
     */
    @Value("${jdbc.pool.timeBetweenEvictionRunsMillis}")
    private Long timeBetweenEvictionRunsMillis;

    /**
     *  最小可移动空闲时间
     */
    @Value("${jdbc.pool.minEvictableIdleTimeMillis}")
    private Long minEvictableIdleTimeMillis;

    /**
     *  取消遗弃
     */
    @Value("${jdbc.pool.removeAbandoned}")
    private Boolean removeAbandoned;


    @Value("${jdbc.pool.removeAbandonedTimeout}")
    private Integer removeAbandonedTimeoutMillis;


    @Value("${jdbc.pool.logAbandoned}")
    private Boolean logAbandoned;


    @Value("${jdbc.pool.poolPreparedStatements}")
    private Boolean poolPreparedStatements;

    @Value("${jdbc.pool.maxPoolPreparedStatementPerConnectionSize}")
    private Integer maxPoolPreparedStatementPerConnectionSize;

    @Value("${jdbc.pool.testOnBorrow}")
    private Boolean testOnBorrow;

    @Value("${jdbc.pool.testOnReturn}")
    private Boolean testOnReturn;

    @Value("${jdbc.pool.testWhileIdle}")
    private Boolean testWhileIdle;

    @Value("${jdbc.pool.validationQuery}")
    private String validationQuery;

    public Integer getInitialSize() {
        return initialSize;
    }

    public void setInitialSize(Integer initialSize) {
        this.initialSize = initialSize;
    }

    public Integer getMaxActive() {
        return maxActive;
    }

    public void setMaxActive(Integer maxActive) {
        this.maxActive = maxActive;
    }

    public Long getMaxWait() {
        return maxWait;
    }

    public void setMaxWait(Long maxWait) {
        this.maxWait = maxWait;
    }

    public Integer getMinIdle() {
        return minIdle;
    }

    public void setMinIdle(Integer minIdle) {
        this.minIdle = minIdle;
    }

    public Long getTimeBetweenEvictionRunsMillis() {
        return timeBetweenEvictionRunsMillis;
    }

    public void setTimeBetweenEvictionRunsMillis(Long timeBetweenEvictionRunsMillis) {
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    }

    public Long getMinEvictableIdleTimeMillis() {
        return minEvictableIdleTimeMillis;
    }

    public void setMinEvictableIdleTimeMillis(Long minEvictableIdleTimeMillis) {
        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
    }

    public Boolean getRemoveAbandoned() {
        return removeAbandoned;
    }

    public void setRemoveAbandoned(Boolean removeAbandoned) {
        this.removeAbandoned = removeAbandoned;
    }

    public Integer getRemoveAbandonedTimeoutMillis() {
        return removeAbandonedTimeoutMillis;
    }

    public void setRemoveAbandonedTimeoutMillis(Integer removeAbandonedTimeoutMillis) {
        this.removeAbandonedTimeoutMillis = removeAbandonedTimeoutMillis;
    }

    public Boolean getLogAbandoned() {
        return logAbandoned;
    }

    public void setLogAbandoned(Boolean logAbandoned) {
        this.logAbandoned = logAbandoned;
    }

    public Boolean getPoolPreparedStatements() {
        return poolPreparedStatements;
    }

    public void setPoolPreparedStatements(Boolean poolPreparedStatements) {
        this.poolPreparedStatements = poolPreparedStatements;
    }

    public Integer getMaxPoolPreparedStatementPerConnectionSize() {
        return maxPoolPreparedStatementPerConnectionSize;
    }

    public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) {
        this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
    }

    public Boolean getTestOnBorrow() {
        return testOnBorrow;
    }

    public void setTestOnBorrow(Boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }

    public Boolean getTestOnReturn() {
        return testOnReturn;
    }

    public void setTestOnReturn(Boolean testOnReturn) {
        this.testOnReturn = testOnReturn;
    }

    public Boolean getTestWhileIdle() {
        return testWhileIdle;
    }

    public void setTestWhileIdle(Boolean testWhileIdle) {
        this.testWhileIdle = testWhileIdle;
    }

    public String getValidationQuery() {
        return validationQuery;
    }

    public void setValidationQuery(String validationQuery) {
        this.validationQuery = validationQuery;
    }
}
